<HTML><HEAD><TITLE>getbit(+Number, +Index, -Result)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Arithmetic</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>getbit(+Number, +Index, -Result)</H1>
Result is the Index'th bit of Number.


<DL>
<DT><EM>Number</EM></DT>
<DD>Integer.
</DD>
<DT><EM>Index</EM></DT>
<DD>Non-negative integer.
</DD>
<DT><EM>Result</EM></DT>
<DD>A variable or integer.
</DD>
</DL>
<H2>Description</H2>
   Returns the Index'th bit of Number, assuming binary two's complement
   representation.  The least significant bit has index zero.
   The result is either 0 or 1.
   This predicate is used by the ECLiPSe compiler to expand evaluable
   arithmetic expressions.  So the call to getbit(Number, Index, Result) is
   equivalent to
<PRE>
    Result is getbit(Number, Index)
</PRE>
   which should be preferred.
<P>
   In coroutining mode, if Number or Index are uninstantiated, the call
   is delayed until these variables are instantiated.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>getbit(+, +, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Number or Index is not instantiated (non-coroutining mode    only).
<DT><EM>(5) type error </EM>
<DD>Number or Index is a number but not an integer.
<DT><EM>(24) number expected </EM>
<DD>Number or Index is not of a numeric type.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      getbit(10, 3, 1).
      getbit(10, 2, 0).
      getbit(10, 99, 0).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/arithmetic/is-2.html">is / 2</A>, <A HREF="../../kernel/arithmetic/clrbit-3.html">clrbit / 3</A>, <A HREF="../../kernel/arithmetic/setbit-3.html">setbit / 3</A>
</BODY></HTML>
